/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Desktop_AddUser.java
 *
 * Created on Mar 31, 2011, 2:30:02 PM
 */
package DesktopGUIpackage;

import Controller.DesktopController;
import Controller.DesktopControllerHelper;
import DTO.Customer;
import Utilities.ResponseMessages;

/**
 *
 * @author edaype
 */
public class Desktop_AddUser extends javax.swing.JPanel {

    private DesktopController desktopController = null;
    private DesktopControllerHelper desktopControllerHelper;
    private Customer customerVO = null;

    /** Creates new form Desktop_AddUser */
    public Desktop_AddUser(DesktopControllerHelper desktopControllerHelper) {
        this.desktopControllerHelper = desktopControllerHelper;
        desktopController = desktopControllerHelper.getDesktopController();
        customerVO = new Customer();
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        ButtonPanel = new javax.swing.JPanel();
        RegisterButton = new javax.swing.JButton();
        ClearButton1 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        ItemPanel = new javax.swing.JPanel();
        PhoneField2 = new javax.swing.JTextField();
        FirstLabel = new javax.swing.JLabel();
        LastField = new javax.swing.JTextField();
        ConfirmLabel = new javax.swing.JLabel();
        EmailLabel = new javax.swing.JLabel();
        LastLabel = new javax.swing.JLabel();
        FirstField = new javax.swing.JTextField();
        PasswordLabel = new javax.swing.JLabel();
        PhoneLabel = new javax.swing.JLabel();
        ConfirmField = new javax.swing.JPasswordField();
        PasswordField = new javax.swing.JPasswordField();
        EmailField = new javax.swing.JTextField();
        PhoneField1 = new javax.swing.JTextField();
        PhoneField3 = new javax.swing.JTextField();
        FirstNameOut = new javax.swing.JLabel();
        LastNameOut = new javax.swing.JLabel();
        EmailOut = new javax.swing.JLabel();
        PassOut = new javax.swing.JLabel();
        PhoneOut = new javax.swing.JLabel();
        ErrorLabel = new javax.swing.JLabel();

        setBackground(new java.awt.Color(255, 255, 255));
        setMinimumSize(new java.awt.Dimension(800, 600));

        ButtonPanel.setBackground(new java.awt.Color(255, 255, 255));

        RegisterButton.setFont(new java.awt.Font("Tahoma", 0, 18));
        RegisterButton.setText("Register");
        RegisterButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RegisterButtonActionPerformed(evt);
            }
        });

        ClearButton1.setFont(new java.awt.Font("Tahoma", 0, 18));
        ClearButton1.setText("Clear Form");
        ClearButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ClearButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout ButtonPanelLayout = new javax.swing.GroupLayout(ButtonPanel);
        ButtonPanel.setLayout(ButtonPanelLayout);
        ButtonPanelLayout.setHorizontalGroup(
            ButtonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ButtonPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(ClearButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(RegisterButton, javax.swing.GroupLayout.PREFERRED_SIZE, 150, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        ButtonPanelLayout.setVerticalGroup(
            ButtonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ButtonPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(ButtonPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ClearButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(RegisterButton, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel2.setFont(new java.awt.Font("Copperplate Gothic Bold", 2, 60));
        jLabel2.setText("Register");

        ItemPanel.setBackground(new java.awt.Color(255, 255, 255));
        ItemPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        PhoneField2.setFont(new java.awt.Font("Tahoma", 0, 24));

        FirstLabel.setFont(new java.awt.Font("Tahoma", 0, 24));
        FirstLabel.setText("First Name");

        LastField.setFont(new java.awt.Font("Tahoma", 0, 24));

        ConfirmLabel.setFont(new java.awt.Font("Tahoma", 0, 24));
        ConfirmLabel.setText("Confirm Pasword");

        EmailLabel.setFont(new java.awt.Font("Tahoma", 0, 24));
        EmailLabel.setText("Email");

        LastLabel.setFont(new java.awt.Font("Tahoma", 0, 24));
        LastLabel.setText("Last Name");

        FirstField.setFont(new java.awt.Font("Tahoma", 0, 24));

        PasswordLabel.setFont(new java.awt.Font("Tahoma", 0, 24));
        PasswordLabel.setText("Password");

        PhoneLabel.setFont(new java.awt.Font("Tahoma", 0, 24));
        PhoneLabel.setText("Phone Number");

        ConfirmField.setFont(new java.awt.Font("Tahoma", 0, 24));

        PasswordField.setFont(new java.awt.Font("Tahoma", 0, 24));

        EmailField.setFont(new java.awt.Font("Tahoma", 0, 24));

        PhoneField1.setFont(new java.awt.Font("Tahoma", 0, 24));

        PhoneField3.setFont(new java.awt.Font("Tahoma", 0, 24));

        FirstNameOut.setText(" ");

        LastNameOut.setText(" ");

        EmailOut.setText(" ");

        PassOut.setText(" ");

        PhoneOut.setText(" ");

        ErrorLabel.setText(" ");

        javax.swing.GroupLayout ItemPanelLayout = new javax.swing.GroupLayout(ItemPanel);
        ItemPanel.setLayout(ItemPanelLayout);
        ItemPanelLayout.setHorizontalGroup(
            ItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ItemPanelLayout.createSequentialGroup()
                .addGroup(ItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(ItemPanelLayout.createSequentialGroup()
                        .addGap(74, 74, 74)
                        .addGroup(ItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(LastLabel)
                            .addComponent(EmailLabel)
                            .addComponent(FirstLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(ItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(FirstField, javax.swing.GroupLayout.PREFERRED_SIZE, 521, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(EmailField)
                            .addComponent(EmailOut, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(FirstNameOut, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(LastNameOut, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(LastField, javax.swing.GroupLayout.DEFAULT_SIZE, 522, Short.MAX_VALUE)))
                    .addGroup(ItemPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(ItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(ConfirmLabel)
                            .addComponent(PasswordLabel)
                            .addComponent(PhoneLabel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(ItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(ItemPanelLayout.createSequentialGroup()
                                .addComponent(PhoneField1, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(PhoneField2, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(PhoneField3, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(ConfirmField)
                            .addComponent(PassOut, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(PhoneOut, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(PasswordField, javax.swing.GroupLayout.DEFAULT_SIZE, 522, Short.MAX_VALUE)
                            .addComponent(ErrorLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 522, Short.MAX_VALUE))))
                .addContainerGap(56, Short.MAX_VALUE))
        );
        ItemPanelLayout.setVerticalGroup(
            ItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ItemPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(ItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(FirstField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(FirstLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(FirstNameOut)
                .addGap(10, 10, 10)
                .addGroup(ItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(LastField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(LastLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(LastNameOut)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(ItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(EmailField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(EmailLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(EmailOut)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(ItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(PasswordField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(PasswordLabel))
                .addGap(18, 18, 18)
                .addGroup(ItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ConfirmField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(ConfirmLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(PassOut)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(ItemPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(PhoneField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(PhoneField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(PhoneField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(PhoneLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(PhoneOut)
                .addGap(18, 18, 18)
                .addComponent(ErrorLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 43, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 326, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 128, Short.MAX_VALUE)
                .addComponent(ButtonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(ItemPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(ItemPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(49, 49, 49)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(ButtonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void RegisterButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RegisterButtonActionPerformed
        // TODO add your handling code here:
        boolean isValid = true;
        isValid = validateFields();
        if (isValid) {

            customerVO.setEmail(EmailField.getText());
            customerVO.setPassCode(new String(PasswordField.getPassword()));//(PasswordField.getPassword().toString());
            customerVO.setPhoneNumber(PhoneField1.getText() + PhoneField2.getText()
                    + PhoneField3.getText());
            customerVO.setFirstName(FirstField.getText());
            customerVO.setLastName(LastField.getText());
            String responseMsg = desktopController.registerCustomer(customerVO);
            if (ResponseMessages.REGISTRATION_FAILED.equalsIgnoreCase(responseMsg)) {
                desktopControllerHelper.changeFrame(6);
            } else if (ResponseMessages.ALREADY_REGISTERED_EMAIL.equalsIgnoreCase(responseMsg)) {
                EmailOut.setText(responseMsg);
            } else if (ResponseMessages.ALREADY_REGISTERED_PHONE.equalsIgnoreCase(responseMsg)) {
                PhoneOut.setText(responseMsg);
            } else {
                 desktopControllerHelper.changeFrame(3);
            }
        }
    }//GEN-LAST:event_RegisterButtonActionPerformed

    private boolean validateFields(){

        boolean isValid = true;


        if("".equalsIgnoreCase(FirstField.getText().trim())){
            isValid = false;
            FirstNameOut.setText("first name is mandatory");
        }else if("".equalsIgnoreCase(LastField.getText().trim())){
            isValid = false;
            LastNameOut.setText("last name is mandatory");
        }else if("".equalsIgnoreCase(EmailField.getText().trim())){
            isValid = false;
            EmailOut.setText("email is mandatory");
        }else if(PasswordField.getPassword().length == 0){
            isValid = false;
            PassOut.setText("password field is mandatory");
        }else if(ConfirmField.getPassword().length == 0){
            isValid = false;
            PassOut.setText("password field is mandatory");
        }else if("".equalsIgnoreCase(PhoneField1.getText().trim())
                || "".equalsIgnoreCase(PhoneField2.getText().trim())
                || "".equalsIgnoreCase(PhoneField3.getText().trim())){
            isValid = false;
            PhoneOut.setText(" phone is mandatory");
        }else if(!(ValidatePhone() && ValidateEmail() && ValidatePassword())){
            isValid = false;
        }else if(PasswordField.getPassword().length != ConfirmField.getPassword().length){
            isValid = false;
            PassOut.setText("password and confirm password field are not matching");
        }

        return isValid;


    }
    private void ClearButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ClearButton1ActionPerformed
        // TODO add your handling code here:
        EmailOut.setText("");
        FirstNameOut.setText("");
        LastNameOut.setText("");
        PassOut.setText("");
        PhoneOut.setText("");
        EmailOut.setText("");
        FirstNameOut.setText("");
        LastNameOut.setText("");
        PassOut.setText("");
        PhoneOut.setText("");
        FirstField.setText("");
        ConfirmField.setText("");
        EmailField.setText("");
        LastField.setText("");
        PasswordField.setText("");
        PhoneField1.setText("");
        PhoneField2.setText("");
        PhoneField3.setText("");
        ErrorLabel.setText("");


    }//GEN-LAST:event_ClearButton1ActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel ButtonPanel;
    private javax.swing.JButton ClearButton1;
    private javax.swing.JPasswordField ConfirmField;
    private javax.swing.JLabel ConfirmLabel;
    private javax.swing.JTextField EmailField;
    private javax.swing.JLabel EmailLabel;
    private javax.swing.JLabel EmailOut;
    private javax.swing.JLabel ErrorLabel;
    private javax.swing.JTextField FirstField;
    private javax.swing.JLabel FirstLabel;
    private javax.swing.JLabel FirstNameOut;
    private javax.swing.JPanel ItemPanel;
    private javax.swing.JTextField LastField;
    private javax.swing.JLabel LastLabel;
    private javax.swing.JLabel LastNameOut;
    private javax.swing.JLabel PassOut;
    private javax.swing.JPasswordField PasswordField;
    private javax.swing.JLabel PasswordLabel;
    private javax.swing.JTextField PhoneField1;
    private javax.swing.JTextField PhoneField2;
    private javax.swing.JTextField PhoneField3;
    private javax.swing.JLabel PhoneLabel;
    private javax.swing.JLabel PhoneOut;
    private javax.swing.JButton RegisterButton;
    private javax.swing.JLabel jLabel2;
    // End of variables declaration//GEN-END:variables

    private boolean ValidateEmail() {
        char[] temp1 = EmailField.getText().toCharArray();
        String temp2 = EmailField.getText().toString();
        int count = 0;
        int size = temp1.length;
        int ascii1 = 0;
        int ascii2 = 0;
        int ascii3 = 0;
        int ascii4 = 0;
        int LastDot = temp2.lastIndexOf(".");
        //Determine if ends something like .com or .ca
        int diff = size - LastDot;


        try {
            ascii1 = EmailField.getText().toLowerCase().charAt(size - 1);
            ascii2 = EmailField.getText().toLowerCase().charAt(size - 2);
            ascii3 = EmailField.getText().toLowerCase().charAt(size - 3);
            ascii4 = EmailField.getText().toLowerCase().charAt(size - 4);

        } catch (StringIndexOutOfBoundsException siobe) {
            return false;
        }

        for (int i = 0; i < temp1.length; i++) {
            if (temp1[i] == '@') {
                count += 1;
            }
        }
        if (diff == 3) {
            if (ascii1 < 97 || ascii1 > 122) {
                EmailOut.setText("Invalid Email Address");
                return false;
            } else if (ascii2 < 97 || ascii2 > 122) {
                EmailOut.setText("Invalid Email Address");
                return false;
            }
        } else if (diff == 4) {
            if (ascii1 < 97 || ascii1 > 122) {
                EmailOut.setText("Invalid Email Address");
                return false;
            } else if (ascii2 < 97 || ascii2 > 122) {
                EmailOut.setText("Invalid Email Address");
                return false;
            } else if (ascii3 < 97 || ascii3 > 122) {
                EmailOut.setText("Invalid Email Address");
                return false;
            }
        } else {
            EmailOut.setText("Invalid Email Address");
            return false;
        }
        if (count != 1) {
            EmailOut.setText("Invalid Email Address");
            return false;
        }
        return true;
    }

    private boolean ValidatePassword() {
        if (PasswordField.getText().length() >= 6) {
            PassOut.setText("");
            if (PasswordField.getText().equals(ConfirmField.getText()) == false) {
                PassOut.setText("Passwords do not match");
                return false;
            } else {
                PassOut.setText("");
            }
        } else {
            PassOut.setText("Password must be at least 6 characters");
            return false;
        }
        return true;
    }

    private boolean ValidatePhone() {
        int AreaCode = 0;
        int Prefix = 0;
        int Suffix = 0;

        try {

            if (PhoneField1.getText().length() != 3) {
                PhoneOut.setText("Invalid Phone Number");
                return false;
            } else if (PhoneField2.getText().length() != 3) {
                PhoneOut.setText("Invalid Phone Number");
                return false;
            } else if (PhoneField3.getText().length() != 4) {
                PhoneOut.setText("Invalid Phone Number");
                return false;
            } else {
                AreaCode = Integer.parseInt(PhoneField1.getText().toString());
                Prefix = Integer.parseInt(PhoneField2.getText().toString());
                Suffix = Integer.parseInt(PhoneField3.getText().toString());
                PhoneOut.setText("");
            }
        } catch (NumberFormatException nfe) {
            PhoneOut.setText("Invalid Phone Number");
            return false;
        }
        return true;
    }
}
